package com.zbkj.crmeb.store.service;

import java.io.IOException;
import java.util.List;

import com.zbkj.crmeb.export.vo.ProductExcelVo;
import com.zbkj.crmeb.store.request.*;
import org.json.JSONException;

import com.baomidou.mybatisplus.extension.service.IService;
import com.common.PageParamRequest;
import com.github.pagehelper.PageInfo;
import com.zbkj.crmeb.chant.model.ChannelMerchant;
import com.zbkj.crmeb.chant.request.ChannelProductRequest;
import com.zbkj.crmeb.chant.vo.ChannelProductVo;
import com.zbkj.crmeb.front.request.IndexStoreProductSearchRequest;
import com.zbkj.crmeb.front.request.ProductRequest;
import com.zbkj.crmeb.store.model.StoreProduct;
import com.zbkj.crmeb.store.model.StoreProductNorm;
import com.zbkj.crmeb.store.response.StoreProductApiResponse;
import com.zbkj.crmeb.store.response.StoreProductAttrValueResponse;
import com.zbkj.crmeb.store.response.StoreProductNormKeywordResponse;
import com.zbkj.crmeb.store.response.StoreProductNormResponse;
import com.zbkj.crmeb.store.response.StoreProductResponse;
import com.zbkj.crmeb.store.response.StoreProductTabsHeader;

/**
* @author Mr.Zhang
* @description StoreProductService 接口
* @date 2020-05-27
*/
public interface StoreProductService extends IService<StoreProduct> {

    /**
     * 标准商品分页列表
     * @Description:  
     * @author daigb 
     * @param @param request
     * @param @param pageParamRequest
     * @param @return
     * @return PageInfo<StoreProductResponse>
     * @throws
     */
    PageInfo<StoreProductNorm> getNormList(StoreProductSearchRequest request, PageParamRequest pageParamRequest);
    
    /**
     * 
     * @Description:  
     * @author daigb 
     * @param @param request
     * @param @param pageParamRequest
     * @param @return
     * @return PageInfo<StoreProductNorm>
     * @throws
     */
    PageInfo<StoreProductNormKeywordResponse> pageNormKeywords(StoreProductSearchRequest request);
    
    /**
     * 将云仓商品加入到标准商品库
     * @Description:  
     * @author daigb 
     * @param @param productId
     * @param @return
     * @return Boolean
     * @throws
     */
    Boolean saveNormProduct(Integer productId);
    
    /**
     * 获取产品列表Admin
     * @param request
     * @param pageParamRequest
     * @return
     */
    PageInfo<StoreProductResponse> getList(StoreProductSearchRequest request, PageParamRequest pageParamRequest);

    PageInfo<StoreProductResponse> getListV2(StoreProductSearchRequest request, PageParamRequest pageParamRequest);
    /**
     * 商品sku分页列表
     * @Description:  
     * @author daigb 
     * @param @param request
     * @param @return
     * @return PageInfo<StoreProductAttrValueResponse>
     * @throws
     */
    PageInfo<StoreProductAttrValueResponse> selectSkuPage(StoreProductSearchRequest request);

    /**
     * H5端使用
     * @param request
     * @param pageParamRequest
     * @param productIdList
     * @return
     */
    List<StoreProduct> getList(StoreProductSearchRequest request, PageParamRequest pageParamRequest,
                               List<Integer> productIdList,Integer merId);


    /**
     * 渠道商品列表 - 分页
     * @param reqParam
     * @param pageParam
     * @return
     */
    PageInfo<ChannelProductVo> selectChannelProductListPage(ChannelProductRequest reqParam, PageParamRequest pageParam);

    /**
     * 渠道商品列表
     * @param reqParam
     * @return
     */
    List<ChannelProductVo> selectChannelProductList(ChannelProductRequest reqParam);

    /**
     * 获取产品列表H5
     * @param request
     * @param pageParamRequest
     * @return
     */
    List<StoreProduct> getList(IndexStoreProductSearchRequest request, PageParamRequest pageParamRequest);

    /**
     * 根据id集合获取商品信息
     * @param productIds id集合
     * @return 商品信息
     */
    List<StoreProduct> getListInIds(List<Integer> productIds);

    List<Integer> listProductIdByStoreName(String productName);

    /**
     * 基本参数获取
     * @param storeProduct 产品参数
     * @return 商品结果
     */
    StoreProduct getByEntity(StoreProduct storeProduct);

    /**
     * 保存产品信息
     * @param storeProductRequest
     * @return
     */
    boolean save(StoreProductRequest storeProductRequest);

    /**
     * 更新产品信息
     * @param storeProductRequest
     * @return
     */
    boolean update(StoreProductRequest storeProductRequest);

    /**
     * 批量上架/下架
     * @param vo
     * @return
     */
    Boolean batchEnabled(BatchEnabledRequest vo);

    /**
     * 验证Barcode
     */
    boolean verifyBarCode(String barCode);

    /**
     * 产品详情
     * @param id
     * @return
     */
    StoreProductResponse getByProductId(int id);

    /**
     * 云仓产品详情(返回关联的所有云仓商品)
     * @param id
     * @return
     */
    StoreProductNormResponse getSupplierByProductId(int id);
    
    /**
     * 云仓产品详情(返回关联的所有云仓商品)
     * @param id
     * @return
     */
    StoreProductNormResponse getSupplierByNormId(int id);

    /**
     * 获取tabsHeader对应数量
     * @return
     */
    List<StoreProductTabsHeader> getTabsHeader(int type);

    /**
     * 添加库存
     * @param request
     * @return
     */
    boolean stockAddRedis(StoreProductStockRequest request);

    /**
     * 根据其他平台url导入产品信息
     * @param url 待倒入平台的url
     * @param tag 待导入平台标识
     * @return 待导入的商品信息
     */
    StoreProductRequest importProductFromUrl(String url, int tag) throws IOException, JSONException;

    /**已弃用 author: daigb
     * 获取推荐商品
     * @param brandId 推荐同品牌商品
     * @param limit 最大数据量
     * @return 推荐商品集合
     */
//    List<StoreProduct> getRecommendStoreProduct(Integer brandId,Integer limit);

    /**
     * 扣减库存加销量
     * @param productId 产品id
     * @param num 商品数量
     * @param type 是否限购 0=不限购
     * @return 扣减结果
     */
    boolean decProductStock(Integer productId, Integer num, String attrValueId, Integer type, Integer activityGroupId);

    boolean decPickingProductStock(Integer productId, Integer num, String attrValueId, Integer type);
    
    /**
     * 利用数据库进行库存加减操作
     * @Description:  
     * @author daigb 
     * @param @param productId
     * @param @param num
     * @param @return
     * @return Boolean
     * @throws
     */
    Boolean subProductStock(Integer productId, Integer stock);

    List<Integer> getSecondaryCategoryByProductId(String productId);

    /**
     * 删除商品
     * @param productId 商品id
     * @return 删除结果
     */
    Boolean deleteProduct(Integer productId);

    /**
     * 恢复已删除商品
     * @param productId 商品id
     * @return 恢复结果
     */
    boolean reStoreProduct(Integer productId);

    /**
     * 后台任务批量操作
     */
    void consumeProductStock();

    /**
     * 通过商品编码查找上是否存在
     * @param barCode
     * @return
     */
    StoreProduct getByBarCode(String barCode);

    int reSortProduct();

    /**
     * 小编推荐打标
     * @param productId
     * @param isBest
     * @return
     */
    boolean updateIsBest(Integer productId,Boolean isBest);

    /**
     * 获取所有上架商品的品牌id
     * @return
     */
    List<Integer> getAllStoreProductBrand();

    /**
     * 设置是否参加活动
     * @param productId
     * @param isPromoter
     * @return
     */
//    boolean updateIsPromoter(Integer productId, Boolean isPromoter);
    
    /**
     * 对外提供商品列表查询
     * @Description:  
     * @author daigb 
     * @param @param key
     * @param @param pageNow
     * @param @param pageSize
     * @return void
     * @throws
     */
    PageInfo<StoreProductApiResponse> listProductByApi(ChannelMerchant channelMerchant, List<String> cateIds, List<String> filterCateIds, 
            List<String> brandIds, String goodsName, String keyWord, Integer goodsId, Integer limitStock, Integer isShow, Integer pageNo, Integer pageSize);
    
    StoreProductApiResponse getProductByApi(ChannelMerchant channelMerchant, String barCode);

    List<StoreProduct> selectProductList(IndexStoreProductSearchRequest request,PageParamRequest pageParamRequest);

    /**
     * 
     * @author cyz
     * @date 2021/4/9 11:25
     * @param request
     * @param pageParamRequest
     * @return com.github.pagehelper.PageInfo<com.zbkj.crmeb.store.response.StoreProductResponse>
     */
    PageInfo<StoreProductResponse> selectZoneProductList(ProductRequest request,PageParamRequest pageParamRequest);

    List<ProductExcelVo> getExprotList(StoreProductSearchRequest request, PageParamRequest pageParamRequest);

    Object updateRealTime(Integer productId);

    /**
     * 修改商品最低价格
     * @param storeProduct 商品信息
     */
    void updateProductMinPrice(StoreProduct storeProduct);

    /**
     * 修改商品的国际编码
     * @param storeProduct
     */
    void updateKeyword(StoreProduct storeProduct);


    /**
     * 修改商品的视频
     * @param storeProduct
     */
    void updateVideo(StoreProductRequest storeProduct);

    void saveOtProduct(StoreProductCrmebRequest storeProductCrmebRequest, StoreProduct storeProduct, Integer stock, Integer merId);

    boolean auditTransferCloud(BestEnabledRequest vo);

    List<Integer> getIsShowProducts(List<Integer> productIdList, Integer merId);

    boolean batchAssociateNormProduct(BatchAssociateNormProductRequest request);

    List<Integer> getBrandsByMerId(Integer merId, String cateId);
}
